////////////////////////////////////////////////////////////////////////////////
// Copyright 2006 CORE Solutions Limited
// All rights reserved.
// PROPRIETARY AND CONFIDENTIAL INFORMATION.
// Use is subject to license terms.
//
// FUNCTION ID      :   VENDOR
// AUTHOR           :   Ric Yik 
// DATE CREATE      :   2006/01/11
// DESCRIPTION      :   a MAINTENANCE ACTION file for the function, VENDOR
//                  :   
//                  :   
//                  :   
//
// MODIFICATION HISTORY:
// DATE         AUTHOR          VERSION NO.         COMMENT
// -----------  --------------  ------------------  -------------------
// 2006/01/11   Ric Yik         1.0                 source is generated.
//
//
//
////////////////////////////////////////////////////////////////////////////////

package com.erp.common.web.multirow;

import com.erp.app.common.util.ProjectCommonUtil;
import com.erp.framework.controller.form.MultiRow;
import com.erp.framework.model.pk.SimpleBasePk;
import com.erp.framework.util.BeanUtil;

/**
 * The base class for MultiRows to be used by SimpleMaintMultiRowForm
 * @author Ric YIK
 *
 * @see com.erp.common.web.multirow.SimpleMaintMultiRowAction
 * @see com.erp.common.web.multirow.SimpleMaintMultiRowForm
 * @see com.erp.common.web.multirow.SimpleMaintMultiRowList
 */
public abstract class SimpleMaintMultiRow extends MultiRow {

    public SimpleMaintMultiRow() {
        super();
    }

    public boolean isRowModeCreating() {
        return ROW_MODE_CREATING.equals(this.getRowMode());
    }

    public void setRowModeCreating() {
        this.setRowMode(ROW_MODE_CREATING);
    }

    public void setRowModeCreate() {
        this.setRowMode(ROW_MODE_CREATE);
    }

    /**
     * Marks this row as deleted. The subclass may override this method to 
     * implement integrity constaints such as cascade delete.
     * 
     * @see com.erp.app.setup.customer.web.CustDeptRow#markAsDeleted(SimpleMaintMultiRowForm)
     * @see com.erp.app.setup.vendor.web.VendorDeptRow#markAsDeleted(SimpleMaintMultiRowForm)
     * 
     * @param form the form which holds all related MultiRows.
     */
    public void markAsDeleted(SimpleMaintMultiRowForm form) {
        this.setIsDelete("checked");
    }

    public boolean isDeleted() {
        return !ProjectCommonUtil.isEmpty(this.getIsDelete());
    }

    public boolean isRowModeModify() {
        return ROW_MODE_MODIFY.equals(this.getRowMode());
    }

    public void setRowModeModify() {
        this.setRowMode(ROW_MODE_MODIFY);
    }

    public SimpleMaintMultiRow makePrototype() {
        try {
            return (SimpleMaintMultiRow) this.getClass().newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }
    }

    public abstract SimpleBasePk getPk();

    public SimpleMaintMultiRow makeCopy() {
        return (SimpleMaintMultiRow) BeanUtil.copyPropertiesDefault(this.makePrototype(), this);
    }

}
